package com.zk.erp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zk.erp.entity.JsonResult;
import com.zk.erp.entity.UserRole;
import com.zk.erp.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zk
 * @since 2021-04-12
 */
@RestController

public class UserRoleController {
    @Autowired
    private IUserRoleService userRoleService;

    //新增userRole
    @RequestMapping(value = "/userRole",method = RequestMethod.POST)
    public JsonResult addUserRole(@RequestBody UserRole userRole){
        userRoleService.save(userRole);
        return new JsonResult(1,null);
    }

    //删除userRole
    @RequestMapping(value = "/userRole/{userId}/{roleId}",method = RequestMethod.DELETE)
    public JsonResult deleteUserRole(@PathVariable("userId")String userId,@PathVariable("roleId")String roleId){
        userRoleService.remove(new QueryWrapper<UserRole>().lambda().eq(UserRole::getRoleId,roleId).eq(UserRole::getUserId,userId));
        return new JsonResult(1,null);
    }
}
